import 'package:dio_log/dio_log.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_audit_app/res/colors.dart';
import 'package:flutter_audit_app/routes/fluro_navigator.dart';
import 'package:flutter_audit_app/ui/home/model/home_grid_item.dart';
import 'package:flutter_audit_app/utils/double_tap_back_exit_app.dart';

///  项目名称：flutter_audit_app
///  Created by leon on 2020/10/20 .

///  首页页面
///
class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    showDebugBtn(context);//显示打印日志框
    return AnnotatedRegion<SystemUiOverlayStyle>(
      ///https://www.jianshu.com/p/15700d9145aa(修改状态栏字体颜色)
      value: SystemUiOverlayStyle.dark,
      child: DoubleTapBackExitApp(
        child: ConstrainedBox(
            constraints: BoxConstraints(),
            child: GridView.count(
              physics: NeverScrollableScrollPhysics(),
              padding: EdgeInsets.only(
                top: height(170),
                left: width(200),
                right: width(220),
                bottom: height(170),
              ),
              crossAxisCount: 4,
              crossAxisSpacing: width(90),
              mainAxisSpacing: height(105),
              childAspectRatio: 3 / 4,
              children: List.generate(8, (index) {
                return Container(
                  height: height(330),
                  width: width(270),
                  child: _buildGridItem(context, homeItemList[index]),
                  // color: Colors.primaries[i % Colors.primaries.length],
                );
              }),
            )),
      ),
    );
  }

  Widget _buildGridItem(BuildContext context, HomeGridItem item) {
    // HomeRouter homeRouter = HomeRouter(item: item);
    return InkWell(
      onTap: () {
        NavigatorUtils.push(context, item.route);
      },
      child: Stack(
        alignment: Alignment.bottomCenter,
        children: [
          Image.asset(
            item.imgPath,
          ),
          Positioned(
            bottom: height(40),
            child: Text(
              item.title,
              textAlign: TextAlign.center,
              style: TextStyle(color: Colors.white, fontSize: 18),
            ),
          )
        ],
      ),
    );
  }
}
